package com.dao;

import java.util.List;

import com.entity.Employee;
import com.util.Page;

@SuppressWarnings("unchecked")
public class EmployeeDao extends BaseDAO {

	/**
	 * 保存EMPloyee
	 * @param emp
	 * @return
	 */
	public boolean saveEmp(Employee emp){
		return this.saveObject(emp);
	}
	
	
	/**
	 * 更新EMPloyee
	 * @param emp
	 * @return
	 */
	public boolean updateEmp(Employee emp){
		return this.updateObject(emp, "where :id=?",emp.getId());
	}
	
	/**
	 * 检查用帐号是否存在 
	 * @param account
	 * @return
	 * @throws Exception
	 */
	public boolean checkEmp(String account) throws Exception{
		List list = this.queryObject(Employee.class,"where :account=?",account);
		return list.isEmpty();
	}
	
	
	/**
	 * 查询对象
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Employee findEmpById(int  id) throws Exception{
		List<Employee> list = null;
		Employee emp = null;
		list = this.queryObject(Employee.class,"where :id=?",id);
		if(list != null && !list.isEmpty()){
			emp = list.get(0);
		}
		return emp;
	}
	
	
	/**
	 * 查询对象
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public boolean delEmpById(String id) throws Exception{
		boolean b = false;
		b = this.executeUpdate("delete from employees where id in("+id+")");
		return b;
	}
	
	/**
	 * 
	 * @return
	 * @throws Exception 
	 */
	public Page emplist(Page page) throws Exception{
		return this.queryObjectForPage(Employee.class, page);
	}
}
